package cn.zjitc.exam.service.impl;

import cn.zjitc.exam.domain.Product;
import cn.zjitc.exam.mapper.ProductMapper;
import cn.zjitc.exam.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * author: 李林凯
 * time:2025/6/18 19:29
 **/
@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    @Override
    public Product findById(int id) {
        return productMapper.findById(id);
    }

    @Override
    public int insert(Product product) {
        return productMapper.insert(product);
    }

    @Override
    public int update(Product product) {
        return productMapper.update(product);
    }

    @Override
    public int delete(int id) {
        return productMapper.delete(id);
    }

    @Override
    public int getProductCount() {
        return productMapper.getProductCount();
    }

    @Override
    public List<Product> getProductByPage(int page, int pageSize) {
        int offset = (page - 1) * pageSize;
        return productMapper.getProductByPage(offset, pageSize);
    }

    @Override
    public List<Product> searchByKeyword(String keyword, int page, int pageSize) {
        int offset = (page - 1) * pageSize;
        return productMapper.searchByKeyword(keyword, offset, pageSize);
    }

    @Override
    public int countByKeyword(String keyword) {
        return productMapper.countByKeyword(keyword);
    }
}
